package com.sy.cloud.guess.config;

import com.gok.pay.wx.IWXPayDomain;
import com.gok.pay.wx.WXPayConfig;
import com.gok.pay.wx.WXPayDomainImpl;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;

/**
 * Created by mac on 2017-12-28.
 */
@Data
@Slf4j
public class WxPayConfig extends WXPayConfig {
    private String appId;
    private String mchId;
    private String key;
    private String domain;
    private String appSecret;
    private String apiSecret;
    private String certString;
    @Override
    protected String getAppID() {
        return appId;
    }

    @Override
    protected String getMchID() {
        return mchId;
    }

    @Override
    public String getKey() {
        return key;
    }

    @Override
    protected InputStream getCertStream() {
        String string = StringUtils.defaultString(certString, "");
        try {
            return new ByteArrayInputStream(string.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            log.error("", e);
        }
        return null;
    }

    @Override
    protected IWXPayDomain getWXPayDomain() {
        return WXPayDomainImpl.instance();
    }

}
